﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using ExportExcel;

namespace BuildData
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            m_config = new ExportConfig();
            UpdateDirs();
        }

        private void UpdateDirs()
        {
            labelExcelPath.Text = m_config.ExcelPath;
            textBoxCodeDir.Text = m_config.ClientCodeOutPutPath;
            textBox1.Text = m_config.ServerCodeOutPutPath;
            comboboxClientLan.Text = m_config.ClientLanguage;
            comboboxServerLan.Text = m_config.ServerLanguage;
        }

        protected override void OnClosed(EventArgs e)
        {
            if (m_config != null)
            {
                m_config.SaveConfig();
            }
            base.OnClosed(e);
        }

        private void OnSelectExcelPath(object sender, EventArgs e)
        {
            using (FolderBrowserDialog dialog = new FolderBrowserDialog())
            {
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    m_config.ExcelPath = dialog.SelectedPath;
                    UpdateDirs();
                }
            }
        }

        private void buttonDescriptionDir_Click(object sender, EventArgs e)
        {
            using (FolderBrowserDialog dialog = new FolderBrowserDialog())
            {
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    //m_config.CsvDescriptionDir = dialog.SelectedPath;
                    UpdateDirs();
                }
            }
        }

        private void buttonCodeDir_Click(object sender, EventArgs e)
        {
            using (FolderBrowserDialog dialog = new FolderBrowserDialog())
            {
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    m_config.ClientCodeOutPutPath = dialog.SelectedPath;
                    UpdateDirs();
                }
            }
        }

        private void buttonBoth_Click(object sender, EventArgs e)
        {
            //if (des.BuildCode(config.CodeDir)
            //    && des.BuildData(config.CsvDir, config.DataDir))
            //{
            //    MessageBox.Show("Build Success!");
            //}
            //else
            //{
            //    MessageBox.Show("Build Failed!");
            //}
        }

        private void button1_Click(object sender, EventArgs e)
        {
            using (FolderBrowserDialog dialog = new FolderBrowserDialog())
            {
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    //m_config.XlsxDir = dialog.SelectedPath;
                    UpdateDirs();
                }
            }
        }


        private void OncomboBoxServerLanChange(object sender, EventArgs e)
        {
            m_config.ServerLanguage = this.comboboxServerLan.Text;
            UpdateDirs();
        }

        private void OncomboBoxClientLanChange(object sender, EventArgs e)
        {
            m_config.ClientLanguage = this.comboboxClientLan.Text;
            UpdateDirs();
        }

        private void OnLabelExcelPathChange(object sender, EventArgs e)
        {
        }

        private ExportConfig m_config = null;

        private void button1_Click_1(object sender, EventArgs e)
        {
            using (FolderBrowserDialog dialog = new FolderBrowserDialog())
            {
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    m_config.ServerCodeOutPutPath = dialog.SelectedPath;
                    UpdateDirs();
                }
            }
        }

        private void textBoxDataDir_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBoxCodeDir_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {
            ExcelReader.singleton.Load(m_config);
        }

        private void button2_Click(object sender, EventArgs e)
        {

        }

        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }
    }
}
